package com.ruoyi.web.controller.statis;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.purchase.domain.PoPurchase;
import com.ruoyi.purchase.service.PoPurchaseService;
import com.ruoyi.storage.domain.RepoCk;
import com.ruoyi.storage.domain.RepoKc;
import com.ruoyi.storage.domain.RepoWare;
import com.ruoyi.storage.service.RepoCkService;
import com.ruoyi.storage.service.RepoKcService;
import com.ruoyi.storage.service.RepoWareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 *  统计 controller
 */
@Controller
@RequestMapping("/statis/view")
public class StatisController extends BaseController {

    @Autowired
    private RepoCkService repoRkService;

    @Autowired
    private RepoWareService repoWareService;

    @Autowired
    private PoPurchaseService poPurchaseService;

    @Autowired
    private RepoKcService repoKcService;



    @RequestMapping("/details/{id}")
    public String details(Model model,@PathVariable String id) {
        PoPurchase poPurchase = new PoPurchase();
        poPurchase.setPurId(id);
        List<PoPurchase> purList = poPurchaseService.findPurList(poPurchase);
        RepoWare repoWare = new RepoWare();
        RepoCk repoRk1 = new RepoCk();
        repoRk1.setMkOrderIndent(id);
        List<RepoCk> repoRks = repoRkService.getAll(repoRk1);
        repoWare.setWareId(repoRks.get(0).getRepoWareId());
        List<RepoWare> repoWares = repoWareService.getList(repoWare);
        model.addAttribute("purList",purList);
        model.addAttribute("repoWare",repoWares);
        model.addAttribute("rks",repoRks);
        return "statis/view/detail";
    }


    @RequestMapping("/detailsList/{pid}")
    @ResponseBody
    public TableDataInfo detailsList(@PathVariable String pid) {
        startPage();
        List<RepoKc> all = repoKcService.getDetailsList(pid);
        System.out.println(all);
        return getDataTable(all);
    }

}
